package com.apanal.qlife.common.jcaptcha;

import com.octo.captcha.service.image.DefaultManageableImageCaptchaService;

/**
 * 验证码管理服务类
 * 
 * 
 * @author shuliangxing
 * 
 * @date 2015-9-10下午5:29:58
 */
public class MyManageableImageCaptchaService extends
		DefaultManageableImageCaptchaService {

	public MyManageableImageCaptchaService(
			com.octo.captcha.service.captchastore.CaptchaStore captchaStore,
			com.octo.captcha.engine.CaptchaEngine captchaEngine,
			int minGuarantedStorageDelayInSeconds, int maxCaptchaStoreSize,
			int captchaStoreLoadBeforeGarbageCollection) {
		super(captchaStore, captchaEngine, minGuarantedStorageDelayInSeconds,
				maxCaptchaStoreSize, captchaStoreLoadBeforeGarbageCollection);
	}

	/**
	 * 判断仓库中是否有相应的验证码存在
	 * 
	 * @param id
	 * @param userCaptchaResponse
	 * @return
	 */
	public boolean hasCapcha(String id, String userCaptchaResponse) {
		if (store.getCaptcha(id) == null) {
			return false;
		}
		return store.getCaptcha(id).validateResponse(userCaptchaResponse);
	}
}
